<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>预约信息添加</title>
		<script type="text/javascript" src="/admin/qrcode/jq.js"></script>
		<script type="text/javascript" src="/admin/qrcode/bot.js"></script>
		<link rel="stylesheet" type="text/css" href="/admin/css/boot.css"></link>
		<link rel="stylesheet" type="text/css" href="/admin/css/sl.css"></link>
		<style>
			label span{color: #ff0000; padding-right: 5px;}
			.control-label{
				width: 120px;
			}
		</style>
	</head>

	<body>
		<h2>添加预约信息</h2>
		<form id="myForm" class="form-horizontal" method="post">
			<div class="form-group">
				<label class="col-sm-1 control-label"><span>*</span>预约人姓名</label>
				<div class="col-sm-9">
					<input required="required" name="userName" style="width: 160px" class="form-control"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-1 control-label"><span>*</span>手机号</label>
				<div class="col-sm-9">
					<input required="required" name="phone" style="width: 160px" class="form-control"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-1 control-label"><span>*</span>预约时间</label>
				<div class="col-sm-2">
					<input name="createTime" class="form-control" style="width: 160px" type="date"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-1 control-label">店铺名称</label>
				<div class="col-sm-2">
					<select name="spencerId" id="name" class="form-control" style="width: 160px">
         				<!--<option value="-1">请选择所属联盟</option>
         				<option value="0">东部联盟</option>
         				<option value="1">西部联盟</option>-->
			      	</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-1 control-label">车辆名称</label>
				<div class="col-sm-2">
					<select name="autoId" id="autoId" class="form-control" style="width: 160px">
						<option value="-1">请选择所属联盟</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-1 control-label"></label>
				<div class="col-sm-9">
					<button id="btnAdd" type="button" class="btn btn-sm btn-info">提&nbsp;交</button>
					<button type="reset"  class="btn btn-sm btn-warning">重&nbsp;置</button>
				</div>
			</div>
		</form>		
	</body>
</html>
<script>
	$(function () {
		$.ajax({
			type: "POST",
			url: "/Admin/selectByName",
			data: "",
			dataType:"json",
			success: function(vo){
				let list = vo;
				//alert(list);
				let str = '<option value="-1">请选择店铺</option>';
				for (let i=0;i<list.length;i++){
					let obj = list[i];
					str+='<option class="auto" value='+obj.spencerId+'>'+obj.spencer.spencerName+'</option>'
					$("#name").html(str);
				}

			}
		})
		//点击时间获取车辆信息
		$("#name").change(function () {
			/*console.log($(this).text(),$(this).val())*/
			let val = $(this).val()
			$.ajax({
				type: "POST",
				url: "/Admin/selectByAuto",
				data: {i:val},
				dataType:"json",
				success: function(vo){
					let list = vo;
					//alert(list);
					let str = '<option value="-1">请选择车辆</option>';
					for (let i=0;i<list.length;i++){
						let obj = list[i];
						str+='<option value='+obj.atuoId+'>'+obj.auto.autoName+'</option>'
						$("#autoId").html(str);
					}
				}
			})
		});




		//提交按钮的单击事件
		$("#btnAdd").click(function () {
			$.ajax({
				type: "POST",
				url: "/Admin/addOrder",
				data: $("#myForm").serialize(),
				dataType:"json",
				success: function(vo){
					if(vo.code==200) {
						window.location.href = "list.html";
					}else{
						alert("添加失败！"+vo.msg);
					}
				}
			});
		});
	});
</script>